// storage存储模块 - vuex
// 用户信息持久化处理
const INFO_KEY = 'hm_shopping_info'
// 存数据
export const setInfo = (info) => {
  localStorage.setItem(INFO_KEY, JSON.stringify(info))
}
// 获取数据
export const getInfo = () => {
  const result = localStorage.getItem(INFO_KEY)
  return result ? JSON.parse(result) : { token: '', userId: '' }
}
// 删除数据
export const removeInfo = () => {
  localStorage.removeItem(INFO_KEY)
}

// 历史记录持久化
const HISTORY_KEY = 'hm_history_list'
// 存数据
export const setHistory = (history) => {
  localStorage.setItem(HISTORY_KEY, JSON.stringify(history))
}
// 获取数据
export const getHistory = () => {
  const result = localStorage.getItem(HISTORY_KEY)
  return result ? JSON.parse(result) : []
}
